﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Model;
using Dal;
using System.Web.SessionState;
using easysql;
namespace Web.service
{
    /// <summary>
    /// DepartmentService 的摘要说明
    /// </summary>
    public class DepartmentService : BaseService<DepartmentModel>, IRequiresSessionState
    {
        private DepartmentDal dal = DalFactory.CreateDepartmentDal();
        public Object query(HttpContext context)
        {
            var bean = requestBean(context);
            return dal.IQuery(bean);
        }

        public void add(HttpContext context)
        {
            var model = requestModel(context);
            dal.IAddOnly(model, "已存在该名称", Restrain.Eq("name", model.name));
        }
        public void modify(HttpContext context)
        {
            var model = requestModel(context);
            dal.IModifyOnly(model, "已存在该名称", Restrain.Eq("name", model.name));
        }
        public void delById(HttpContext context)
        {
            int id = int.Parse(context.Request["id"]);
            dal.IDelById(id);
        }
       
        //public Object tree(HttpContext context)
        //{
        //    List<DepartmentModel> list = dal.IQuery(null);
        //    if (!string.IsNullOrEmpty(context.Request["insertRoot"]))
        //    {
        //        list.Insert(0, new DepartmentModel() { name = "全部", open = true, icon = "/icon/application_view_columns.png" });
        //    }
        //    return list;
        //}

    }
}